﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.IO.Packaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VisionApp.UserManager.Service;

namespace VisionApp.Startup.ViewModels
{
    public partial class LoginViewModel:ObservableObject
    {
        public event Action<bool> LoginCompleted;
        [ObservableProperty]
        private string userName;

        public string Password {  get; set; }

        private readonly IUserManagerService userManagerService;

        public LoginViewModel(IUserManagerService userManagerService)
        {
            this.userManagerService = userManagerService;
        }
        [RelayCommand]
        private void Login()
        {
            if (UserName == null)
            { 
                MessageBox.Show("用户名不能为空","错误"); 
                return; 
            }
            if (Password == null)
            {
                MessageBox.Show("密码不能为空", "错误");
                return;
            }
            var result=userManagerService.Login(UserName, Password);
            
            LoginCompleted?.Invoke(result);
        }
    }
}
